//
//  NativeAdViewController.m
//  HZZFAdSDK_Example
//
//  Copyright © 2025 早范. All rights reserved.
//

#import "NativeAdViewController.h"
#import <HZZFAdSDK/HZZFAdSDKNativeAd.h>
#import <HZZFAdSDK/HZZFAdSDKAdapter.h>
#import <HZZFAdSDK/HZZFUtilsKit.h>
@interface NativeAdViewController ()<HZZFAdSDKNativeAdDelegate>
@property (nonatomic, strong)HZZFAdSDKNativeAd *nativeAd;
@property (nonatomic ,strong)UIView<HZZFAdapterNativeAdViewDelegate> *adview;
@end

@implementation NativeAdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"自渲染";
    CGFloat width = (self.view.frame.size.width - 150) / 2;
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(width, 150, 150, 40);
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor orangeColor];
    btn.layer.cornerRadius = 20;
    
    [self.view addSubview:btn];
    [btn setTitle:@"显示广告" forState:UIControlStateNormal];
//    [btn setTitleColor:[UIColor blackColor] forState:0];
    [btn addTarget:self action:@selector(loadNativeAd) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *closebtn = [UIButton buttonWithType:UIButtonTypeCustom];
    closebtn.frame = CGRectMake(width, 200, 150, 40);
    
    [closebtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    closebtn.backgroundColor = [UIColor orangeColor];
    closebtn.layer.cornerRadius = 20;
    [self.view addSubview:closebtn];
    [closebtn setTitle:@"关闭广告" forState:UIControlStateNormal];
//    [closebtn setTitleColor:[UIColor blackColor] forState:0];
    [closebtn addTarget:self action:@selector(closeAd) forControlEvents:UIControlEventTouchUpInside];
}
- (void)closeAd{
    [self.adview hzzf_close];
}
- (void)loadNativeAd{
    
    HZZFAdSDKNativeAd *nativeAd = [[HZZFAdSDKNativeAd alloc]init];
    _nativeAd = nativeAd;
    _nativeAd.delegate = self;
    _nativeAd.controller = self;
    _nativeAd.posId = @"99908725";
    [_nativeAd load:1];
}
/**
信息流原生广告请求成功
@param nativeAd 广告实例
@param adViewArray 广告模板集合
*/
- (void)HZZF_nativeAdSucessToLoad:(HZZFAdSDKNativeAd *)nativeAd
                     adViewArray:(NSArray<__kindof
                                  UIView<HZZFAdapterNativeAdViewDelegate> *> *)adViewArray{
    self.adview = [adViewArray firstObject];
    [self.adview hzzf_registViews:@[self.adview]];
    self.adview.frame = CGRectMake(0, 300, self.view.frame.size.width,self.view.frame.size.width * 9 / 16);
    [self.view addSubview:self.adview];
    
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.frame = CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.width * 9 / 16);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.adview addSubview:imageView];
    
    HZZFAdapterNativeAdData *adData = [self.adview hzzf_nativeAdData];
    if (!kHZZFStringIsEmpty(adData.imageUrl)) {
        [imageView hzzf_setImageWithURL:[NSURL URLWithString:adData.imageUrl]];
    }
    
}


/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)HZZF_nativeAdFailToLoad:(HZZFAdSDKNativeAd *)nativeAd
                         error:(NSError *)error{
    NSString *message = [error localizedDescription];
    
  
}

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)HZZF_nativeAdClicked:(HZZFAdSDKNativeAd *)nativeAd
                     adView:(__kindof UIView<HZZFAdapterNativeAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL{

}

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)HZZF_nativeAdClose:(HZZFAdSDKNativeAd *)nativeAd
                   adView:(__kindof UIView<HZZFAdapterNativeAdViewDelegate> *)adView{

}

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)HZZF_nativeAdExposure:(HZZFAdSDKNativeAd *)nativeAd
                      adView:(__kindof UIView<HZZFAdapterNativeAdViewDelegate> *)adView{

}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
